import React, { useEffect, useState } from "react"

const Countdown = () => {
    const [countDownNum, setCountDownNum] = useState(10)
    console.log('rerender', countDownNum);
    useEffect(() => {
        let timer = setInterval(() => {
            setCountDownNum(countDownNum - 1)
        }, 1000)
        countDownNum < 1 && clearInterval(timer)
        return () => {
            clearInterval(timer)
        }
    }, [countDownNum])
    return (
        <div>{countDownNum}</div>
    )
}

export default Countdown
